package br.com.lp3.livraria.controller.clientes;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.lp3.livraria.dao.ClienteDao;
import br.com.lp3.livraria.model.Cliente;

@WebServlet(urlPatterns="/view/clientes/deletar.do")
public class DeletarClienteServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Long id = Long.parseLong(req.getParameter("id"));
		ClienteDao clienteDao = new ClienteDao();
		
		Cliente cliente = clienteDao.buscarPorId(id);
		String nome = cliente.getNome();
		
		clienteDao.deletar(cliente);
		
		resp.sendRedirect("visualizar.do?deletado="+nome);
	}
}
